<?php
// +----------------------------------------------------------------------
// | PHP [ JUST YOU ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2017 http://www.jyphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Albert <albert_p@foxmail.com>
// +----------------------------------------------------------------------
namespace App\Extend;

use JYPHP\Core\Exception\Handler;
use JYPHP\Core\Exception\HttpParamException;
use JYPHP\Core\Http\Request;

class ExceptionHandler extends Handler
{
    public function render(Request $request, \Throwable $exception)
    {
        if ($exception instanceof  ApiException) {
            return [
                'errCode' => $exception->getCode(),
                'errMsg' => $exception->getMessage()
            ];
        }
        if ($exception instanceof HttpParamException) {
            return [
                'errCode' => $exception->getCode(),
                'errMsg' => $exception->getMessage()
            ];
        }
        return parent::render($request, $exception); // TODO: Change the autogenerated stub
    }
}